package com.mzj.saas.mservice.property.controller;

import com.mzj.saas.annotation.RepeatSubmit;
import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.property.service.ComplainSuggestService;
import com.mzj.saas.mservice.property.vo.ComplainSuggestApiData;
import com.mzj.saas.mservice.property.vo.ComplainSuggestVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 投诉建议
 *
 * @author hikari
 * @since 2021-05-13
 */
@RestController
@RequestMapping("/property/complainSuggest")
public class ComplainSuggestController {
    @Autowired
    private ComplainSuggestService complainSuggestService;

    /**
     * 投诉建议列表
     *
     * @param accessToken
     * @param username 发起人
     * @param mobile 发起人电话
     * @param startTime 发起时间
     * @param endTime 结束时间
     * @param type 类型 1、建议 2、投诉
     * @param status 状态 1、待处理 2、已处理
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @GetMapping
    public ResultBean<ComplainSuggestApiData<ComplainSuggestVO>> list(@RequestHeader String accessToken,
                                                                      @RequestParam(required = false) String username,
                                                                      @RequestParam(required = false) String mobile,
                                                                      @RequestParam(required = false) String startTime,
                                                                      @RequestParam(required = false) String endTime,
                                                                      @RequestParam(required = false) Integer type,
                                                                      @RequestParam(required = false) Integer status,
                                                                      @RequestParam(required = false) String houseId,
                                                                      @RequestParam(defaultValue = "0") Integer pageNumber,
                                                                      @RequestParam(defaultValue = "5") Integer pageSize) {
        return complainSuggestService.listV2(accessToken, username, mobile, startTime, endTime, type, status, houseId,
                pageNumber, pageSize);
    }

    /**
     * 投诉建议詳情
     *
     * @param accessToken
     * @param id 投诉建议id
     * @return
     */
    @GetMapping("/{id}")
    public ResultBean<ComplainSuggestVO> selectComplainSuggestByid(@RequestHeader String accessToken,
                                                                      @PathVariable("id") Long id) {
        return complainSuggestService.selectComplainSuggestByid(accessToken, id);
    }

    /**
     * 上报投诉建议
     *
     * @param accessToken
     * @param complainSuggestVO
     * @return
     */
    @PostMapping
    @RepeatSubmit
    public ResultBean<ComplainSuggestVO> save(@RequestHeader String accessToken,
                                              @RequestBody ComplainSuggestVO complainSuggestVO) {
        return complainSuggestService.save(accessToken, complainSuggestVO);
    }

    /**
     * 处理投诉建议
     *
     * @param accessToken
     * @param id
     * @return
     */
    @PostMapping("/solve/{id}")
    public ResultBean<ComplainSuggestVO> solve(@RequestHeader String accessToken, @PathVariable Long id) {
        return complainSuggestService.solve(accessToken, id);
    }

    /**
     * 撤销投诉建议
     * @param accessToken
     * @param id
     * @return
     */
    @GetMapping("/delete/{id}")
    @RepeatSubmit
    public ResultBean<Object> delete(@RequestHeader String accessToken, @PathVariable Long id) {
        return complainSuggestService.delete(accessToken, id);
    }


}
